<!-- 
<template>
    <div class="all-events">
        <h2>所有热点事件</h2>
        <div v-for="(event, index) in hotEvents" :key="index" class="event-item">
            <div class="event-details">
                <h4 class="event-title">{{ event.title }}</h4>
                <p class="event-detail">{{ event.detail }}</p>
                <p class="event-time">{{ formatTime(event.time) }}</p>
            </div>
            <div v-if="index < hotEvents.length - 1" class="event-separator"></div>
        </div>
    </div>
</template> -->
<!-- 
<script>
import axios from 'axios'
axios.defaults.withCredentials = true
export default {
    data() {
        return {
            hotEvents: []
        };
    },
    methods: {
        async getEvent() {
            this.loginError = '';
            try {
                const response = await axios.get('http://47.108.80.35:6060/hot_event/get_event');
                console.log("请求事件", response);
                this.hotEvents = response.data.data.map(event => ({
                    title: event.title,
                    detail: event.content,
                    time: event.event_time
                }));
                console.log("事件", this.hotEvents);
            } catch (error) {
                console.log("请求失败", error);
            }
        },
        formatTime(time) {
            const date = new Date(time);
            const year = date.getFullYear();
            const month = String(date.getMonth() + 1).padStart(2, '0');
            const day = String(date.getDate()).padStart(2, '0');
            const hours = String(date.getHours()).padStart(2, '0');
            const minutes = String(date.getMinutes()).padStart(2, '0');
            const seconds = String(date.getSeconds()).padStart(2, '0');
            return `${year}-${month}-${day} ${hours}:${minutes}:${seconds}`;
        }
    },
    created() {
        this.getEvent();
    }
};
</script> -->
<!-- 
<style scoped>
.all-events {
    padding: 16px;
    max-width: 800px;
    margin: 0 auto;
}

.event-item {
    position: relative;
    margin-bottom: 16px;
}

.event-details {
    display: flex;
    flex-direction: column; /* 修改为列布局 */
}

.event-title {
    margin: 0 0 8px 8px;
    font-size: 18px;
    text-align: left;
}

.event-detail {
    margin: 0 0 8px 8px;
    color: #666;
    white-space: nowrap; /* 防止换行 */
    overflow: hidden; /* 隐藏溢出内容 */
    text-overflow: ellipsis; /* 显示省略号 */
    max-width: 100%; /* 确保宽度不超过容器 */
}

.event-time {
    margin: 0 0 0 8px;
    color: #999;
    font-size: 14px;
    text-align: right;
}

.event-separator {
    position: absolute;
    bottom: 0;
    left: 0;
    width: 100%;
    height: 1px;
    background-color: #ccc;
}
</style> -->


<!-- AllEvents.vue -->
<template>
    <div class="all-events">
        <h2 class="page-title">所有热点事件</h2>
        <div v-for="(event, index) in hotEvents" :key="index" class="event-item">
            <div class="event-details">
                <h4 class="event-title">{{ event.title }}</h4>
                <p class="event-detail">{{ event.detail }}</p>
                <p class="event-time">{{ formatTime(event.time) }}</p>
            </div>
            <div v-if="index < hotEvents.length - 1" class="event-separator"></div>
        </div>
    </div>
</template>

<script>
import axios from 'axios'
axios.defaults.withCredentials = true
export default {
    data() {
        return {
            hotEvents: []
        };
    },
    methods: {
        async getEvent() {
            this.loginError = '';
            try {
                const response = await axios.get('http://47.108.80.35:6060/hot_event/get_event');
                console.log("请求事件", response);
                this.hotEvents = response.data.data.map(event => ({
                    title: event.title,
                    detail: event.content,
                    time: event.event_time
                }));
                console.log("事件", this.hotEvents);
            } catch (error) {
                console.log("请求失败", error);
            }
        },
        formatTime(time) {
            const date = new Date(time);
            const year = date.getFullYear();
            const month = String(date.getMonth() + 1).padStart(2, '0');
            const day = String(date.getDate()).padStart(2, '0');
            const hours = String(date.getHours()).padStart(2, '0');
            const minutes = String(date.getMinutes()).padStart(2, '0');
            const seconds = String(date.getSeconds()).padStart(2, '0');
            return `${year}-${month}-${day} ${hours}:${minutes}:${seconds}`;
        }
    },
    created() {
        this.getEvent();
    }
};
</script>

<style scoped>
.all-events {
    padding: 16px;
    width: 100%;
    max-width: 800px;
    margin: 0 auto;
    box-sizing: border-box;
}

.page-title {
    font-size: 1.5rem;
    text-align: center;
    margin-bottom: 24px;
    color: #333;
}

.event-item {
    position: relative;
    margin-bottom: 16px;
    padding: 16px;
    border-radius: 8px;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.1);
    background-color: #fff;
    transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.event-item:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

.event-details {
    display: flex;
    flex-direction: column;
}

.event-title {
    margin: 0 0 12px 0;
    font-size: 1.2rem;
    text-align: left;
    color: #333;
    font-weight: 600;
}

.event-detail {
    margin: 0 0 12px 0;
    color: #666;
    line-height: 1.5;
    text-align: justify;
}

.event-time {
    margin: 0;
    color: #999;
    font-size: 0.9rem;
    text-align: right;
    align-self: flex-end;
}

.event-separator {
    position: absolute;
    bottom: -8px;
    left: 0;
    width: 100%;
    height: 1px;
    background-color: #eee;
}

/* 平板设备 */
@media (min-width: 768px) {
    .all-events {
        padding: 24px;
    }
    
    .page-title {
        font-size: 2rem;
        margin-bottom: 32px;
    }
    
    .event-item {
        padding: 20px;
        margin-bottom: 20px;
    }
    
    .event-title {
        font-size: 1.4rem;
        margin-bottom: 14px;
    }
    
    .event-detail {
        font-size: 1.1rem;
        margin-bottom: 14px;
    }
    
    .event-time {
        font-size: 1rem;
    }
}

/* 桌面设备 */
@media (min-width: 1024px) {
    .all-events {
        padding: 32px;
        max-width: 900px;
    }
    
    .page-title {
        font-size: 2.2rem;
    }
    
    .event-item {
        padding: 24px;
    }
    
    .event-title {
        font-size: 1.5rem;
    }
    
    .event-detail {
        font-size: 1.15rem;
    }
}

/* 小屏幕设备优化 */
@media (max-width: 480px) {
    .all-events {
        padding: 12px;
    }
    
    .page-title {
        font-size: 1.3rem;
        margin-bottom: 20px;
    }
    
    .event-item {
        padding: 12px;
        margin-bottom: 12px;
    }
    
    .event-title {
        font-size: 1.1rem;
        margin-bottom: 10px;
    }
    
    .event-detail {
        font-size: 0.95rem;
        margin-bottom: 10px;
    }
    
    .event-time {
        font-size: 0.85rem;
    }
}
</style>